home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 106_01.zip / CRL.LIB < prev    next >
Text File  |  1993-06-26  |  7KB  |  297 lines

  1. ;                crl.lib
  2. ;
  3. ;    Copyright (C) 1980, M J Maney
  4. ;
  5. ;    First created 8/16/80
  6. ;    Last revised 8/29/80 14:00
  7. ;
  8. ;    This file contains some macro definitions designed for asembling
  9. ;    code to the "crl" format employed by the BDS C compiler and linker.
  10. ;
  11. ;
  12. ARG1    equ    3F7H
  13. ARG2    equ    ARG1+2
  14. ARG3    equ    ARG2+2
  15. ARG4    equ    ARG3+2
  16. ARG5    equ    ARG4+2
  17. ARG6    equ    ARG5+2
  18. ;
  19. ;
  20. ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;
  21. ;
  22. ;                PROC
  23. ;
  24. ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;
  25. ;    PROC is the function header macro. It must be used to introduce each
  26. ;    function in the source module before the object code for that module.
  27. ;    The syntax is:
  28. ;
  29. ;    PROC    func_name {,<needed functions list>}
  30. ;
  31. ;    NB: if there is more than one "needed function", then the list
  32. ;    MUST be protected by "<",">"...see MAC manual for explanation
  33. ;    of the syntax.
  34. ;
  35. ;    To maintain compatibility with the 1.32 release of C, all function
  36. ;    names must be upper-case alpha-numerics, and should also be limited
  37. ;    to a maximum of eight characters in length. The needed function list
  38. ;    must be enclosed in broken brackets if there is more than one needed
  39. ;    function.
  40. ;
  41. ;    I have modified DSTR to allow the inclusion of the underscore
  42. ;    character in function names. NB that the name in the PROC or PEND
  43. ;    statement MUST use the '?' character in place of the underscore.
  44. ;    Thus, the PROC for a function to be called '_bc' is:
  45. ;
  46. ;    PROC    ?BC
  47. ;
  48. ;
  49. ;    PROC creates the directory entry, the needed functions list, and the
  50. ;    dummy vector table for the function. The body of the module begins
  51. ;    immediately following the PROC declaration, and continues to the
  52. ;    next PEND. PROCs and PENDs may NOT be nested!
  53. ;
  54. PROC    macro    ?name,?list
  55. @nxdir    set    100H        ;;initialize a few assembe-time variables
  56. @nxcod    set    305H
  57. ;;
  58. PROC    macro    name,list    ;;after initializations, re-define PROC
  59.     local    start
  60. ?rp    set    1            ;;reset relocation counter
  61.     org    @nxdir            ;;create directory entry
  62.     DSTR    name
  63.     dw    @nxcod-100H
  64. @nxdir    set    $
  65.     org    @nxcod
  66.     if not nul list            ;;list of needed functions
  67.     irp    fn,<list>
  68.     DSTR    fn
  69.     endm
  70.     endif
  71.     db    0
  72.     dw    &name$end - &name$ent    ;;length of module code
  73. &name$ent:
  74. @base    set    &name$ent
  75.     if not nul list            ;;dummy vectors
  76.     bra    start
  77.     irp    fn,<list>
  78. fn    set    $
  79.     jmp    0
  80.     endm
  81.     endif
  82. start    endm            ;;end of inner definition
  83. ;;
  84.     PROC    ?name,<?list>    ;;invoke new definition to create header
  85.     endm
  86. ;
  87. ;
  88. ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;
  89. ;
  90. ;                PEND
  91. ;
  92. ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;
  93. ;    PEND must be invoked to close each function definition. The syntax is:
  94. ;
  95. ;    PEND    func_name
  96. ;
  97. ;    The func_name must match the last (active) PROC's func_name, and must
  98. ;    be a proper function name. PEND creates the label needed to compute
  99. ;    the length of the body and the list of relocation parameters.
  100. ;    PEND also handles the directory termination.
  101. ;
  102. PEND    macro    name
  103. &name$end    equ    $    ;;label
  104.     dw    ?rp - 1        ;;number of relocation parameters
  105. ?n    set    1
  106.     rept    ?rp - 1        ;;generate reloc. list
  107.     GDW    ra,%?n
  108. ?n    set    ?n + 1
  109.     endm
  110. @nxcod    set    $        ;;set @nxcod for next function
  111.     org    @nxdir
  112.     db    80H        ;;terminate directory list
  113.     dw    @nxcod-100H    ;;and put in file limit
  114.     endm
  115. ;
  116. ;
  117. ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;
  118. ;
  119. ;            relocatable op-code mnemonics
  120. ;
  121. ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;
  122. ;    These pseudo-ops produce normal 8080 ops, but have the virtue of
  123. ;    adding the necessary addresses to an assemble-time list of reloc
  124. ;    parameters, which PEND uses to create the relocation parameter
  125. ;    list.
  126. ;
  127. ;
  128. BRA    macro    adr        ;;relocatable jump
  129.     ADDRP    $+1-@base
  130.     jmp    adr - @base
  131.     endm
  132. ;
  133. ;
  134. BZ    macro    adr        ;;relocatable conditional jump
  135.     ADDRP    $+1-@base
  136.     jz    adr - @base
  137.     endm
  138. ;
  139. ;
  140. BNZ    macro    adr        ;;relocatable conditional jump
  141.     ADDRP    $+1-@base
  142.     jnz    adr - @base
  143.     endm
  144. ;
  145. ;
  146. BC    macro    adr        ;;relocatable conditional jump
  147.     ADDRP    $+1-@base
  148.     jc    adr - @base
  149.     endm
  150. ;
  151. ;
  152. BNC    macro    adr        ;;relocatable conditional jump
  153.     ADDRP    $+1-@base
  154.     jnc    adr - @base
  155.     endm
  156. ;
  157. ;
  158. BM    macro    adr        ;;relocatable conditional jump
  159.     ADDRP    $+1-@base
  160.     jm    adr - @base
  161.     endm
  162. ;
  163. ;
  164. BP    macro    adr        ;;relocatable conditional jump
  165.     ADDRP    $+1-@base
  166.     jp    adr - @base
  167.     endm
  168. ;
  169. ;
  170. BPO    macro    adr        ;;relocatable conditional jump
  171.     ADDRP    $+1-@base
  172.     jpo    adr - @base
  173.     endm
  174. ;
  175. ;
  176. BPE    macro    adr        ;;relocatable conditional jump
  177.     ADDRP    $+1-@base
  178.     jpe    adr - @base
  179.     endm
  180. ;
  181. ;
  182. BSR    macro    adr        ;;relocatable subroutine call
  183.     ADDRP    $+1-@base
  184.     call    adr - @base
  185.     endm
  186. ;
  187. ;
  188. LHLR    macro    adr        ;;load HL direct from relocatable address
  189.     ADDRP    $+1-@base
  190.     lhld    adr - @base
  191.     endm
  192. ;
  193. ;
  194. SHLR    macro    adr        ;;store HL direct to relocatable address
  195.     ADDRP    $+1-@base
  196.     shld    adr - @base
  197.     endm
  198. ;
  199. ;
  200. LDAR    macro    adr        ;;load A direct from relocatable address
  201.     ADDRP    $+1-@base
  202.     lda    adr - @base
  203.     endm
  204. ;
  205. ;
  206. STAR    macro    adr        ;;store A direct to relocatable address
  207.     ADDRP    $+1-@base
  208.     sta    adr - @base
  209.     endm
  210. ;
  211. ;
  212. LXIR    macro    reg,adr        ;;load rp immediate with relocatable address
  213.     ADDRP    $+1-@base
  214.     lxi    reg,adr - @base
  215.     endm
  216. ;
  217. ;
  218. ;    RELOC was added after I mentioned this library to Leor. He says
  219. ;    that this (or something very like it) is the basis of a library
  220. ;    that he has, and which is being distributed with the 1.4 release
  221. ;    of the C package. Personally, I prefer the pseudo-ops above, but
  222. ;    this is somewhat a matter of taste. Also, the conditional calls
  223. ;    have not been implemented as pseudo-ops, so RELOC may occasionally
  224. ;    be necessary, whether you prefer it or not.
  225. ;
  226. ;    RELOC can be used with any three-byte operation, provided that the
  227. ;    source format has the address operand as the LAST or only operand.
  228. ;    For example, a typical use would be:
  229. ;
  230. ;    RELOC <cnz foo>
  231. ;
  232. ;    Which will expand to generate the code-producing line:
  233. ;
  234. ;    cnz foo-@base
  235. ;
  236. ;    Of course, RELOC also adds the address of the address field of the
  237. ;    generated code to the list of relocation parameters. Note that the
  238. ;    protection of the entire operation is required, so that it will be
  239. ;    handled as a single parameter by MAC. 'nuff said.
  240. ;
  241. RELOC    macro    op
  242.     ADDRP    $+1-@base
  243.     op-@base
  244.     endm
  245. ;
  246. ;
  247. ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;
  248. ;
  249. ;            utility routines for crl.lib
  250. ;
  251. ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;
  252. ;    There are several little utility routines that the above macros
  253. ;    need. They follow here.
  254. ;
  255. ;
  256. ADDRP    macro    adr        ;;adr an address to the reloc list
  257.     GSET    ra,%?rp,adr
  258. ?rp    set    ?rp + 1
  259.     endm
  260. ;
  261. ;
  262. GSET    macro    nam,num,val    ;;set generated symbol to val
  263. nam&num    set    val
  264.     endm
  265. ;
  266. ;
  267. GDW    macro    nam,num        ;;generate dw with generated symbol
  268.     dw    nam&num
  269.     endm
  270. ;
  271. ;
  272. DSTR    macro    string        ;;generate byte string with B7=1 in last byte
  273.     local    ?n,?c
  274.     STRLEN    <string>,?n        ;;set ?n = strlen(string)
  275.     irpc    C,<string>
  276.     if    '&C' eq '?'
  277. ?c    set    '_'
  278.     else
  279. ?c    set    '&C'
  280.     endif
  281. ?n    set    ?n - 1
  282.     if    ?n EQ 0
  283.     db    ?c OR 80H
  284.     else
  285.     db    ?c
  286.     endif
  287.     endm
  288.     endm
  289. ;
  290. ;
  291. STRLEN    macro    string,len
  292. len    set    0
  293.     irpc    C,<string>
  294. len    set    len + 1
  295.     endm
  296.     endm
  297.